﻿<common:LayoutAwarePage x:Class="KouDai.Metro.Views.VariableGridViewDemo"
                        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                        xmlns:Controls="using:KouDai.Metro.Controls"
                        xmlns:common="using:KouDai.Metro.Common"
                        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                        xmlns:local="using:KouDai.Metro.Views"
                        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                        x:Name="pageRoot"
                        DataContext="{Binding Main,
                                              Source={StaticResource Locator}}"
                        mc:Ignorable="d">

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <common:LayoutAwarePage.Resources>

        <CollectionViewSource x:Name="groupedItemsViewSource" Source="{Binding Items}" />

    </common:LayoutAwarePage.Resources>

    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <!--  Back button and page title  -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton"
                    Click="GoBack"
                    IsEnabled="{Binding Frame.CanGoBack,
                                        ElementName=pageRoot}"
                    Style="{StaticResource BackButtonStyle}" />
            <TextBlock x:Name="pageTitle"
                       Grid.Column="1"
                       IsHitTestVisible="false"
                       Style="{StaticResource PageHeaderTextStyle}"
                       Text="{StaticResource AppName}" />
        </Grid>


        <ScrollViewer x:Name="itemGridScrollViewer"
                      Grid.Row="1"
                      Margin="0,-3,0,0"
                      AutomationProperties.AutomationId="ItemGridScrollViewer">

            <Controls:VariableGridView Margin="116,0,40,46"
                                       IsItemClickEnabled="True"
                                       ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
                                       SelectionMode="None">
                <Controls:VariableGridView.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="2">
                            <Grid.ChildrenTransitions>
                                <TransitionCollection>
                                    <EntranceThemeTransition />
                                </TransitionCollection>
                            </Grid.ChildrenTransitions>
                            <Image HorizontalAlignment="Stretch"
                                   VerticalAlignment="Stretch"
                                   Source="{Binding ImageUrlForIphone}"
                                   Stretch="UniformToFill" />
                        </Grid>
                    </DataTemplate>
                </Controls:VariableGridView.ItemTemplate>
                <Controls:VariableGridView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VariableSizedWrapGrid ItemHeight="100"
                                               ItemWidth="250"
                                               MaximumRowsOrColumns="4" />
                    </ItemsPanelTemplate>
                </Controls:VariableGridView.ItemsPanel>
                <!--
                    <Controls:VariableGridView.GroupStyle>
                    <GroupStyle>
                    <GroupStyle.Panel>
                    <ItemsPanelTemplate>
                    <VariableSizedWrapGrid ItemHeight="100"
                    ItemWidth="250"
                    MaximumRowsOrColumns="4" />
                    </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                    </GroupStyle>
                    </Controls:VariableGridView.GroupStyle>
                -->
            </Controls:VariableGridView>
        </ScrollViewer>


        <VisualStateManager.VisualStateGroups>

            <!--  Visual states reflect the application's view state  -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape" />
                <VisualState x:Name="Filled" />

                <!--  The entire page respects the narrower 100-pixel margin convention for portrait  -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Padding">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="96,136,86,56" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!--
                    The back button and title have different styles when snapped, and the list representation is substituted
                    for the grid displayed in all other view states
                -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}" />
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
